<style lang="less">
</style>
<template>
  <div>
    <Card ref="card">
      <!-- <p slot="title">工作量汇总</p> -->
      <div slot="title">
        <p>绩效核算</p>
      </div>
      <a href="#" slot="extra" @click.prevent="GetWorkCount(1)">刷新</a>
      <Row>
        <Col span="4">
          <Select
            v-model="year"
            size="large"
            placeholder="2020年"
            style="width: 100px; margin: 0"
          >
            <Option
              v-for="item in yearList"
              :value="item.value"
              :key="item.value"
              >{{ item.label }}</Option
            >
          </Select>
        </Col>
        <Col span="20">
          <DatePicker
            type="date"
            placeholder="开始日期"
            size="large"
            style="width: 200px"
            v-model="sdate"
            format="yyyy年MM月dd日"
          ></DatePicker>
          <DatePicker
            style="margin-left: 10px; width: 200px"
            type="date"
            placeholder="结束日期"
            size="large"
            v-model="edate"
            format="yyyy年MM月dd日"
          ></DatePicker>
          <Button
            style="margin-left: 10px"
            size="large"
            type="primary"
            icon="ios-search"
            v-on:click="GetWorkCount(2)"
            >查询</Button
          >
        </Col>
      </Row>
      <br />
      <Tabs v-model="month" @on-click="GetWorkCount(1)">
        <TabPane label="一月" name="1"></TabPane>
        <TabPane label="二月" name="2"></TabPane>
        <TabPane label="三月" name="3"></TabPane>
        <TabPane label="四月" name="4"></TabPane>
        <TabPane label="五月" name="5"></TabPane>
        <TabPane label="六月" name="6"></TabPane>
        <TabPane label="七月" name="7"></TabPane>
        <TabPane label="八月" name="8"></TabPane>
        <TabPane label="九月" name="9"></TabPane>
        <TabPane label="十月" name="10"></TabPane>
        <TabPane label="十一月" name="11"></TabPane>
        <TabPane label="十二月" name="12"></TabPane>
        <TabPane label="全年汇总" name="13"></TabPane>
      </Tabs>
    </Card>
    <Table
      class="margin-top-10"
      border
      :columns="tableTitle"
      :data="tableData"
      ref="table"
      :height="tableHeight"
    ></Table>
    <Modal
      :mask-closable="false"
      footer-hide
      v-model="modelDetail"
      title="积分详情"
      width="900"
      draggable
    >
      <Table
        border
        :loading="loadingDetail"
        :columns="tableTitleDetail"
        :data="tableDataDetail"
        ref="table"
        height="450"
      ></Table>
      <Row class="margin-top-10">
        <Page
          :total="total"
          :current="pPage"
          :page-size="pSize"
          :page-size-opts="[50, 100, 300, 500, 1000, 2000, 5000]"
          @on-change="
            (s) => {
              pPage = s;
              SearchDetail();
            }
          "
          @on-page-size-change="
            (p) => {
              pSize = p;
              pPage = 1;
              SearchDetail();
            }
          "
          show-total
          show-sizer
        />
      </Row>
    </Modal>

    <Modal
      :mask-closable="false"
      footer-hide
      v-model="modelDetail3"
      title="绩效详情"
      width="1200"
      draggable
    >
      
      <Row>
        <Col span="24">
          <h3>
            低保核查共计{{ tableDataDetail3.length }}天，平均每天核查积分为
            {{ caleDBCount.avgCount }} 分，日最高积分为
            {{ caleDBCount.maxCount }} ，日最低积分
            {{ caleDBCount.minCount }} 分,累计积分为{{ caleDBCount.amount }}分。
          </h3>
          <h3>
            救助核查共计{{ tableDataDetail2.length }}天，平均每天核查积分为
            {{ caleJZCount.avgCount }} 分，日最高积分为
            {{ caleJZCount.maxCount }} ，日最低积分
            {{ caleJZCount.minCount }} 分,累计积分为{{ caleJZCount.amount }}分。
          </h3>
        </Col>
      </Row>
      <br />
      <Row>
        <Col span="8">
          <Table
            border
            :loading="loadingDetail3"
            :columns="tableTitleDetail3"
            :data="tableDataDetail3"
            ref="table"
            height="450"
          ></Table>
        </Col>
        <Col span="8">
          <Table
            border
            :loading="loadingDetail2"
            :columns="tableTitleDetail2"
            :data="tableDataDetail2"
            ref="table"
            height="450"
          ></Table>
        </Col>
        <Col span="8">
          <Table
            border
            :loading="loadingDetail4"
            :columns="tableTitleDetail4"
            :data="tableDataDetail4"
            ref="table"
            height="450"
          ></Table>
        </Col>
      </Row>
    </Modal>
  </div>
</template>
<script>
import { Message, Modal } from "view-design";
import {
  GetWorkCount,
  SearchWorkDetail,
  SearchWorkDetailByGroup,
} from "@/api/data";
import { SearchDBWorkDetail, SearchDBWorkDetailByDate } from "@/api/dbdata";
import { SearchJZWorkDetail, SearchJZWorkDetailByDate } from "@/api/jzdata";
import { SearchRijianWorkDetail } from "@/api/rijian";
import { SearchXfyWorkDetail } from "@/api/xfy";
import dayjs from "dayjs";
export default {
  name: "employee_work",
  data() {
    return {
      modelDetail: false,
      modelDetail2: false,
      modelDetail3: false,
      loadingDetail: false,
      loadingDetail2: false,
      loadingDetail3: false,
      DetailType: 0,
      year: 2020,
      yearList: [
        {
          label: "2019年",
          value: "2019",
        },
        {
          label: "2020年",
          value: "2020",
        },
        {
          label: "2021年",
          value: "2021",
        },
        {
          label: "2022年",
          value: "2022",
        },
        {
          label: "2023年",
          value: "2023",
        },
        {
          label: "2024年",
          value: "2024",
        },
        {
          label: "2025年",
          value: "2025",
        },
        {
          label: "2026年",
          value: "2026",
        },
      ],
      sdate: dayjs().year() + "年" + (dayjs().month() + 1) + "月" + "01日",
      edate: dayjs().format("YYYY年MM月DD日"),
      finalSdate: "",
      finalEdate: "",
      tableHeight: 450,
      month: "1",
      tableTitle: [
        {
          title: "姓名",
          key: "EmployeeName",
          width: 200,
          align: "center",
        },
        {
          title: "合计积分",
          minWidth: 100,
          align: "center",
          render: (h, params) => {
            return h(
              "a",
              {
                props: {
                  color: "#2d8cf0",
                },
                style: {
                  fontWeight: "bold",
                },
              },
              params.row.AllCount
            );
          },
        },
        {
          title: "评估积分",
          minWidth: 100,
          align: "center",
          render: (h, params) => {
            return h(
              "a",
              {
                props: {
                  color: "#2d8cf0",
                },
                on: {
                  click: () => {
                    this.modelDetail = true;
                    this.tempEmpid = params.row.EmployeeId;
                    this.DetailType = 1;
                    this.SearchDetail();
                  },
                },
              },
              params.row.AssessCount
            );
          },
        },

        {
          title: "低保核查积分",
          minWidth: 100,
          align: "center",
          render: (h, params) => {
            return h(
              "a",
              {
                props: {
                  color: "#2d8cf0",
                },
                on: {
                  click: () => {
                    this.modelDetail = true;
                    this.tempEmpid = params.row.EmployeeId;
                    this.DetailType = 2;
                    this.SearchDetail();
                  },
                },
              },
              params.row.DBCount
            );
          },
        },
        {
          title: "救助核查积分",
          minWidth: 100,
          align: "center",
          render: (h, params) => {
            return h(
              "a",
              {
                props: {
                  color: "#2d8cf0",
                },
                on: {
                  click: () => {
                    this.modelDetail = true;
                    this.tempEmpid = params.row.EmployeeId;
                    this.DetailType = 3;
                    this.SearchDetail();
                  },
                },
              },
              params.row.JZCount
            );
          },
        },
        {
          title: "日间评定积分",
          minWidth: 100,
          align: "center",
          render: (h, params) => {
            return h(
              "a",
              {
                props: {
                  color: "#2d8cf0",
                },
                on: {
                  click: () => {
                    this.modelDetail = true;
                    this.tempEmpid = params.row.EmployeeId;
                    this.DetailType = 4;
                    this.SearchDetail();
                  },
                },
              },
              params.row.RijianCount
            );
          },
        },
        {
          title: "幸福院评定积分",
          minWidth: 100,
          align: "center",
          render: (h, params) => {
            return h(
              "a",
              {
                props: {
                  color: "#2d8cf0",
                },
                on: {
                  click: () => {
                    this.modelDetail = true;
                    this.tempEmpid = params.row.EmployeeId;
                    this.DetailType = 5;
                    this.SearchDetail();
                  },
                },
              },
              params.row.XFYCount
            );
          },
        },
        {
          title: "操作",
          key: "action",
          width: 150,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "success",
                    size: "small",
                  },
                  style: {
                    marginRight: "5px",
                  },
                  on: {
                    click: () => {
                      this.modelDetail3 = true;
                      this.tempEmpid = params.row.EmployeeId;
                      this.SearchDBWorkDetailByDate();
                      this.SearchJZWorkDetailByDate();
                      this.SearchWorkDetailByGroup();
                    },
                  },
                },
                "详情"
              ),
            ]);
          },
        },
        // {
        //   title: "修改量",
        //   key: "ModiCount",
        //   align: "center"
        // },
        // {
        //   title: "修改率",
        //   align: "center",
        //   key: "ModiRate",
        //   render: (h, params) => {
        //     if (params.row.ModiRate != null) {
        //       return h("div", params.row.ModiRate + "%");
        //     }
        //   }
        // },
        {
          title: " ",
          align: "center",
        },
      ],
      tableData: [],
      tempEmpid: "",
      total: 0,
      pPage: 1,
      pSize: 50,
      tableTitleDetail: [
        {
          title: "序号",
          key: "R_INDEX",
          width: 100,
          align: "center",
        },
        {
          title: "评估时间",
          key: "sys_CreateDate",
          align: "center",
        },
        {
          title: "评估对象",
          key: "Name",
          align: "center",
        },
      ],
      tableDataDetail: [],
      total2: 0,
      pPage2: 1,
      pSize2: 50,
      tableTitleDetail2: [
        {
          title: "序号",
          type: "index",
          width: 80,
          align: "center",
        },
        {
          title: "日期",
          key: "sys_CreateDate",
          width: 150,
          align: "center",
        },
        {
          title: "救助核查积分",
          key: "JZCount",
          align: "center",
        },
      ],
      tableDataDetail2: [],
      tableTitleDetail3: [
        {
          title: "序号",
          type: "index",
          width: 80,
          align: "center",
        },
        {
          title: "日期",
          key: "sys_CreateDate",
          width: 150,
          align: "center",
        },
        {
          title: "低保核查积分",
          key: "DBCount",
          align: "center",
        },
      ],
      tableDataDetail3: [],
      tableTitleDetail4: [
        {
          title: "序号",
          type: "index",
          width: 80,
          align: "center",
        },
        {
          title: "项目",
          key: "GroupName",
          align: "center",
        },
        {
          title: "能力评估积分",
          width: 100,
          key: "AssessCount",
          align: "center",
        },
      ],
      tableDataDetail4: [],
    };
  },
  methods: {
    dayjs,
    GetWorkCount(type) {
      let vm = this;

      if (type == 2) {
        if (typeof vm.sdate == "object") {
          vm.sdate = vm.dayjs(vm.sdate).format("YYYY-MM-DD");
        }
        if (typeof vm.edate == "object") {
          vm.edate = vm.dayjs(vm.edate).format("YYYY-MM-DD");
        }
        vm.finalSdate = vm.sdate;
        vm.finalEdate = vm.edate;
      } else {
        if (vm.month == 13) {
          vm.finalSdate = vm.year + "-01-01";
          vm.finalEdate = vm.year + "-12-31";
        } else {
          var lastDay = new Date(vm.year, vm.month, 0).getDate();
          var month = vm.month;
          if (month.length < 2) {
            month = "0" + month;
          }
          if (lastDay < 10) {
            lastDay = "0" + lastDay;
          }
          vm.finalSdate = vm.year + "-" + month + "-01";
          vm.finalEdate = vm.year + "-" + month + "-" + lastDay;
        }
      }

      var reqData = {
        sdate: vm.finalSdate,
        edate: vm.finalEdate,
      };
      GetWorkCount(reqData).then((res) => {
        const data = res.data;
        if (data.Type == 1) {
          vm.tableData = data.Data;
        } else {
          Message.error(data.Message);
        }
      });
    },
    SearchWorkDetail() {
      let vm = this;
      vm.tableDataDetail = [];
      var reqData = {
        empid: vm.tempEmpid,
        page: vm.pPage,
        size: vm.pSize,
        sdate: vm.finalSdate,
        edate: vm.finalEdate,
      };
      vm.loadingDetail = true;
      SearchWorkDetail(reqData).then((res) => {
        vm.loadingDetail = false;
        const data = res.data;
        if (data.Type == 1) {
          vm.total = data.Data.Total;
          vm.tableDataDetail = data.Data.Rows;
        } else {
          Message.error(data.Message);
        }
      });
    },
    SearchDBWorkDetail() {
      let vm = this;
      vm.tableDataDetail = [];
      var reqData = {
        empid: vm.tempEmpid,
        page: vm.pPage,
        size: vm.pSize,
        sdate: vm.finalSdate,
        edate: vm.finalEdate,
      };
      vm.loadingDetail = true;
      SearchDBWorkDetail(reqData).then((res) => {
        vm.loadingDetail = false;
        const data = res.data;
        if (data.Type == 1) {
          vm.total = data.Data.Total;
          vm.tableDataDetail = data.Data.Rows;
        } else {
          Message.error(data.Message);
        }
      });
    },
    SearchJZWorkDetail() {
      let vm = this;
      vm.tableDataDetail = [];
      var reqData = {
        empid: vm.tempEmpid,
        page: vm.pPage,
        size: vm.pSize,
        sdate: vm.finalSdate,
        edate: vm.finalEdate,
      };
      vm.loadingDetail = true;
      SearchJZWorkDetail(reqData).then((res) => {
        vm.loadingDetail = false;
        const data = res.data;
        if (data.Type == 1) {
          vm.total = data.Data.Total;
          vm.tableDataDetail = data.Data.Rows;
        } else {
          Message.error(data.Message);
        }
      });
    },
    SearchRijianWorkDetail() {
      let vm = this;
      vm.tableDataDetail = [];
      var reqData = {
        empid: vm.tempEmpid,
        page: vm.pPage,
        size: vm.pSize,
        sdate: vm.finalSdate,
        edate: vm.finalEdate,
      };
      vm.loadingDetail = true;
      SearchRijianWorkDetail(reqData).then((res) => {
        vm.loadingDetail = false;
        const data = res.data;
        if (data.Type == 1) {
          vm.total = data.Data.Total;
          vm.tableDataDetail = data.Data.Rows;
        } else {
          Message.error(data.Message);
        }
      });
    },
    SearchXfyWorkDetail() {
      let vm = this;
      vm.tableDataDetail = [];
      var reqData = {
        empid: vm.tempEmpid,
        page: vm.pPage,
        size: vm.pSize,
        sdate: vm.finalSdate,
        edate: vm.finalEdate,
      };
      vm.loadingDetail = true;
      SearchXfyWorkDetail(reqData).then((res) => {
        vm.loadingDetail = false;
        const data = res.data;
        if (data.Type == 1) {
          vm.total = data.Data.Total;
          vm.tableDataDetail = data.Data.Rows;
        } else {
          Message.error(data.Message);
        }
      });
    },
    SearchDetail() {
      let vm = this;
      if (vm.DetailType == 1) {
        //评估
        vm.tableTitleDetail = [
          {
            title: "序号",
            key: "R_INDEX",
            width: 100,
            align: "center",
          },
          {
            title: "评估时间",
            width: 200,
            key: "sys_CreateDate",
            align: "center",
          },
          {
            title: "评估对象",
            width: 150,
            key: "Name",
            align: "center",
          },
          {
            title: "所属项目",
            key: "GroupName",
            align: "center",
          },
        ];
        vm.SearchWorkDetail();
      } else if (vm.DetailType == 2) {
        //低保
        vm.tableTitleDetail = [
          {
            title: "序号",
            key: "R_INDEX",
            width: 100,
            align: "center",
          },
          {
            title: "核查时间",
            width: 200,
            key: "sys_CreateDate",
            align: "center",
          },
          {
            title: "核查对象",
            width: 150,
            key: "Name",
            align: "center",
          },
          {
            title: "所属项目",
            key: "GroupName",
            align: "center",
          },
        ];
        vm.SearchDBWorkDetail();
      } else if (vm.DetailType == 3) {
        //救助
        vm.tableTitleDetail = [
          {
            title: "序号",
            key: "R_INDEX",
            width: 100,
            align: "center",
          },
          {
            title: "核查时间",
            width: 200,
            key: "sys_CreateDate",
            align: "center",
          },
          {
            title: "核查对象",
            key: "Name",
            width: 150,
            align: "center",
          },
          {
            title: "所属项目",
            key: "GroupName",
            align: "center",
          },
        ];
        vm.SearchJZWorkDetail();
      } else if (vm.DetailType == 4) {
        //日间
        vm.tableTitleDetail = [
          {
            title: "序号",
            key: "R_INDEX",
            width: 100,
            align: "center",
          },
          {
            title: "核查时间",
            width: 200,
            key: "CheckTime",
            align: "center",
          },
          {
            title: "核查机构",
            width: 200,
            key: "Name",
            align: "center",
          },
          {
            title: "所属项目",
            key: "GroupName",
            align: "center",
          },
        ];
        vm.SearchRijianWorkDetail();
      } else if (vm.DetailType == 5) {
        //幸福院
        vm.tableTitleDetail = [
          {
            title: "序号",
            key: "R_INDEX",
            width: 100,
            align: "center",
          },
          {
            title: "核查时间",
            width: 200,
            key: "CheckTime",
            align: "center",
          },
          {
            title: "核查机构",
            width: 200,
            key: "Name",
            align: "center",
          },
          {
            title: "所属项目",
            key: "GroupName",
            align: "center",
          },
        ];
        vm.SearchXfyWorkDetail();
      } else if (vm.DetailType == 6) {
        //机构
      }
    },

    SearchDBWorkDetailByDate() {
      let vm = this;
      var reqData = {
        empid: vm.tempEmpid,
        sdate: vm.finalSdate,
        edate: vm.finalEdate,
      };
      vm.loadingDetail3 = true;
      SearchDBWorkDetailByDate(reqData).then((res) => {
        vm.loadingDetail3 = false;
        const data = res.data;
        if (data.Type == 1) {
          vm.tableDataDetail3 = data.Data;
        } else {
          Message.error(data.Message);
        }
      });
    },
    SearchJZWorkDetailByDate() {
      let vm = this;
      var reqData = {
        empid: vm.tempEmpid,
        sdate: vm.finalSdate,
        edate: vm.finalEdate,
      };
      vm.loadingDetail2 = true;
      SearchJZWorkDetailByDate(reqData).then((res) => {
        vm.loadingDetail2 = false;
        const data = res.data;
        if (data.Type == 1) {
          vm.tableDataDetail2 = data.Data;
        } else {
          Message.error(data.Message);
        }
      });
    },

    SearchWorkDetailByGroup() {
      let vm = this;
      var reqData = {
        empid: vm.tempEmpid,
        sdate: vm.finalSdate,
        edate: vm.finalEdate,
      };
      vm.loadingDetail4 = true;
      SearchWorkDetailByGroup(reqData).then((res) => {
        vm.loadingDetail4 = false;
        const data = res.data;
        if (data.Type == 1) {
          vm.tableDataDetail4 = data.Data;
        } else {
          Message.error(data.Message);
        }
      });
    },
  },
  created() {},
  computed: {
    caleDBCount() {
      if (this.tableDataDetail3.length > 0) {
        var maxCount = 0;
        var minCount = 10000000;
        var avgCount = 0;
        var amount = 0;
        this.tableDataDetail3.forEach((e) => {
          amount += e.DBCount;
          if (maxCount < e.DBCount) {
            maxCount = e.DBCount;
          }
          if (minCount > e.DBCount) {
            minCount = e.DBCount;
          }
        });
        avgCount = (amount / this.tableDataDetail3.length).toFixed(1);

        return {
          maxCount,
          minCount,
          avgCount,
          amount: amount.toFixed(1),
        };
      } else {
        return {};
      }
    },
    caleJZCount() {
      if (this.tableDataDetail2.length > 0) {
        var maxCount = 0;
        var minCount = 10000000;
        var avgCount = 0;
        var amount = 0;
        this.tableDataDetail2.forEach((e) => {
          amount += e.JZCount;
          if (maxCount < e.JZCount) {
            maxCount = e.JZCount;
          }
          if (minCount > e.JZCount) {
            minCount = e.JZCount;
          }
        });
        avgCount = (amount / this.tableDataDetail2.length).toFixed(1);

        return {
          maxCount,
          minCount,
          avgCount,
          amount: amount.toFixed(1),
        };
      } else {
        return {};
      }
    },
  },
  watch: {
    year: function (newQuestion, oldQuestion) {
      this.GetWorkCount(1);
    },
  },
  mounted() {
    var cardHeight = this.$refs.card.$el.offsetHeight;
    this.tableHeight = window.innerHeight - cardHeight - 200;
    var date = new Date();
    var month = date.getMonth() + 1;
    this.month = month + "";
    this.year = dayjs(new Date()).format("YYYY");
  },
};
</script>
